/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.jomijushi.fid.servicios;

import com.jomijushi.fid.dao.PersonaEmpresaImplementsDAO;
import com.jomijushi.fid.dao.PersonaEmpresaInterfazDAO;
import com.jomijushi.fid.dao.ClienteImplementsDAO;
import com.jomijushi.fid.dao.ClienteInterfazDAO;
import com.jomijushi.fid.dominio.FidCliente;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;

/**
 *
 * @author Miguel
 */
public class ClienteImplementsService implements ClienteInterfazService {
    
    private ClienteInterfazDAO clienteDAO = new ClienteImplementsDAO();
    private EntityManagerFactory emf;

    @PersistenceContext
    public void setEntityManagerFactory(EntityManagerFactory emf) {
        this.emf = emf;
    }

    public void crearCliente(FidCliente cliente) {
        EntityManager em = emf.createEntityManager();
        em.getTransaction().begin();
        clienteDAO.setEntityManager(em);
        clienteDAO.persist(cliente);
        em.getTransaction().commit();
        em.close();
    }

    public List<FidCliente> listarClientes(String valorKey, String buscar, boolean b, int c, int d, String orden)
    {
        EntityManager em = emf.createEntityManager();
        try {
            clienteDAO.setEntityManager(em);
            List<FidCliente> lst = clienteDAO.listarClientes(valorKey, buscar, b, c, d, orden);
            return lst;
        } finally {
            em.close();
        }
    }
}